package day17.tcp;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

public class TestClient {
    public static void main(String[] args) {
        File file = new File("D:\\图片视频\\jmj.jpg");
        // 连接服务端
        try(Socket socket = new Socket("127.0.0.1", 9527);
            InputStream is = new FileInputStream(file);
            ) {
            // 获取了socket的输出流，给服务端发送数据的流
            BufferedOutputStream os = new BufferedOutputStream(socket.getOutputStream(), 1024 * 1024 * 50);
            byte[] data = new byte[1024 * 1024];
            int len = 0;
            while((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
            os.flush();
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
